package com.tduck.cloud.api.web.controller;

import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.tduck.cloud.api.web.ao.FormReportAO;
import com.tduck.cloud.common.util.Result;
import com.tduck.cloud.form.dto.EvaluatedScoreDTO;
import com.tduck.cloud.form.dto.FormItemScoreDTO;
import com.tduck.cloud.form.dto.FormTextItemScoreDTO;
import com.tduck.cloud.form.service.UserFormDataService;
import com.tduck.cloud.form.service.UserFormItemService;
import com.tduck.cloud.form.service.UserFormService;
import com.tduck.cloud.form.vo.FormReportDataVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 测评报告数据查询
 *
 * @author Guard Baby
 * @date 2023/05/09
 */
@Slf4j
@RestController
@RequestMapping("/report")
public class UserFormReportController {

    @Autowired
    private FormReportAO formReportAO;
    @Autowired
    private UserFormDataService userFormDataService;
    @Autowired
    private UserFormItemService userFormItemService;
    @Autowired
    private UserFormService userFormService;

    @GetMapping("/getAverage")
    public Result<List<EvaluatedScoreDTO>> queryScoreDataByFormKey(String formKey) {
        Assert.notEmpty(formKey, "参数错误");
        return Result.success(formReportAO.queryScoreDataByFormKey(formKey));
    }

    @GetMapping("/getItemScore")
    public Result<List<FormItemScoreDTO>> queryItemScoreByFormKey(String formKey) {
        Assert.notEmpty(formKey, "参数错误");
        return Result.success(formReportAO.queryItemScoreByFormKey(formKey));
    }

    @GetMapping("/getReport")
    public Result<FormReportDataVO> getReport(String formKey, Long evaluated) {
        log.debug("formKey:{},evaluated:{}", formKey, evaluated);
        Assert.notEmpty(formKey, "参数错误");
        FormReportDataVO formReportDataVO = formReportAO.getReport(formKey, evaluated);
        log.debug("form:{}", formReportDataVO);
        return Result.success(formReportDataVO);
    }

    @GetMapping("/getItemText")
    public Result<List<FormTextItemScoreDTO>> getItemText(String formKey, Long evaluated) {
        Assert.notEmpty(formKey, "参数错误");
        Assert.notNull(evaluated, "参数错误");
        return Result.success(formReportAO.queryFormTextItemScore(formKey, evaluated));
    }


}
